<template>
  <div class="box">
    <header>
      <van-nav-bar title="添加地址" @click-left="$router.back()">
        <template #left>
          <van-icon name="arrow-left" size="18" color="black" />
        </template>
      </van-nav-bar>
    </header>
    <main>
      <van-address-edit :area-list="areaList" show-postal show-delete show-set-default show-search-result
        :search-result="searchResult" :area-columns-placeholder="['请选择', '请选择', '请选择']" @save="onSave" />
    </main>

  </div>
</template>

<script>
import {goToAddress} from "../api/address";

import Vue from 'vue';
import { AddressEdit,Area,Toast  } from 'vant';
// 省市区选择组件
import { areaList } from '@vant/area-data';

Vue.use(AddressEdit);
Vue.use(Area);
Vue.use(Toast);
export default {
  data () {
    return {
      areaList,
    }
  },
  methods: {
    onSave(content) {
      console.log(content);
      goToAddress({
        userid: localStorage.getItem("userid"),
        name: content.name,
        tel:content.tel,
        province:content.province,
        city:content.city,
        county:content.county,
        addressDetail:content.addressDetail,
        isDefault:content.isDefault
      }).then(()=>{
        Toast('添加成功');
        setTimeout(()=>{
            this.$router.back()
        },1000)
      })
    },
  },
}
</script>

<style scoped>

</style>